home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / Queue / Base_Queue.C next >
C/C++ Source or Header  |  1992-04-13  |  5KB  |  162 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Created: MBN 08/29/89 -- Initial design and implementation
  13. // Updated: MBN 10/11/89 -- Changed "current_position" to "curpos" 
  14. // Updated: LGO 02/02/90 -- Re-wrote practically everything
  15. // Updated: MJF 03/12/90 -- Added group names to RAISE
  16. // Updated: VDN 02/21/92 -- New lite version
  17. //
  18. // The  CoolQueue class is publicly derived from the Generic class  and is used
  19. // to implement  non-type specific  functionality  for the  parameterized CoolQueue
  20. // class. In this  manner, code common to all  instances of the CoolQueue class can
  21. // be shared to reduce code replication. The CoolQueue class implements  a circular
  22. // buffer of  a   user-specified type.   This is accomplished   by   using  the
  23. // parameterized type capability  of C++. The CoolQueue  will grow  dynamically  as
  24. // necessary with the amount of growth determined by the value of an allocation
  25. // size slot. Fixed length  queues  are also supported by  setting the value of
  26. // the allocation size slot to INVALID.
  27. //
  28.  
  29. #ifndef BASE_QUEUEH                // If no class definition
  30. #include <cool/Base_Queue.h>            // Include definition file
  31. #endif
  32.  
  33. // long length() -- Return the number of elements in this CoolQueue
  34. // Input:           None
  35. // Output:          Integer representing number of elements
  36.  
  37. long CoolQueue::length () const {
  38.   long len = in - out;
  39.   return (len < 0) ? limit + len : len;
  40. }
  41.  
  42. // void set_growth_ratio(float) -- Set growth percentage of this CoolQueue
  43. // Input:                          Float ratio and character string type
  44. // Output:                         None
  45.  
  46. void CoolQueue::set_growth_ratio (float ratio, const char* Type) {
  47. #if ERROR_CHECKING
  48.   if (ratio < 0.0) {                // If non-positive growth
  49.     //RAISE (Error, SYM(CoolQueue), SYM(Negative_Ratio),
  50.     printf ("CoolQueue<%s>::set_growth_ratio(): Negative growth ratio %f.\n",
  51.         Type, ratio);
  52.     abort ();
  53.   }
  54. #endif
  55.   this->growth_ratio_s = ratio;            // Set growth ratio
  56. }
  57.  
  58.  
  59. // void set_alloc_size(int) -- Set the default allocation size growth rate
  60. // Input:                      Integer size and character string type
  61. // Output:                     None
  62.  
  63. void CoolQueue::set_alloc_size (int size, const char* Type) {
  64. #if ERROR_CHECKING
  65.   if (size < 0 && size != INVALID) {        // If index out of range
  66.     //RAISE (Error, SYM(CoolQueue), SYM(Negative_Size),
  67.     printf ("CoolQueue<%s>::set_alloc_size(): Negative growth size %d.\n",
  68.         Type, size);
  69.     abort ();
  70.   }
  71. #endif
  72.   this->alloc_size = size;            // Set growth size
  73. }
  74.  
  75.  
  76. // CoolQueue () -- Empty constructor for the CoolQueue class
  77. // Input:      None
  78. // Output:     None
  79.  
  80. CoolQueue::CoolQueue () {
  81.   this->limit = 0;                // Initialize size
  82.   this->in = this->out = 0;            // Intialize first/last pointer
  83.   this->alloc_size = QUEUE_MEM_BLK_SZ;        // Default
  84. }
  85.  
  86.  
  87. // CoolQueue (long) -- Constructor that specifies number of elements
  88. // Input:          Integer number of elements
  89. // Output:         None
  90.  
  91. CoolQueue::CoolQueue (long n) {
  92.   this->limit = n;                // Element capacity
  93.   this->in = this->out = 0;            // Intialize first/last pointer
  94.   this->alloc_size = QUEUE_MEM_BLK_SZ;        // Default
  95. }
  96.  
  97.  
  98. // CoolQueue (CoolQueue&) -- Constructor for reference to another CoolQueue
  99. // Input:            CoolQueue reference
  100. // Output:           None
  101.  
  102. CoolQueue::CoolQueue (const CoolQueue& s) {
  103.   alloc_size = s.alloc_size;            // Set alloc size
  104.   if (alloc_size == INVALID)
  105.     alloc_size = QUEUE_MEM_BLK_SZ;
  106.   this->in = s.in;                // Set in
  107.   this->out = s.out;                // Set out
  108.   this->limit = s.limit;            // Set limit
  109. }
  110.  
  111.  
  112. // ~CoolQueue -- Destructor for CoolQueue class that frees up storage
  113. // Input:    None
  114. // Output:   None
  115.  
  116. CoolQueue::~CoolQueue () {
  117. }
  118.  
  119.  
  120. // look_error -- Error message for parameterized CoolQueue<Type>::look() method
  121. // Input:        Character string of type
  122. // Output:       None
  123.  
  124. void CoolQueue::look_error (const char* Type) {
  125.   //RAISE (Error, SYM(CoolQueue), SYM(No_Elements),
  126.   printf ("CoolQueue<%s>::look(): No elements in queue.\n", Type);
  127.   abort ();
  128. }
  129.  
  130.  
  131. // value_error -- Error message for parameterized CoolQueue<Type>::value() method
  132. // Input:         Character string of type
  133. // Output:        None
  134.  
  135. void CoolQueue::value_error (const char* Type) {
  136.   //RAISE (Error, SYM(CoolQueue), SYM(Invalid_Cpos),
  137.   printf ("CoolQueue<%s>::value(): Invalid current position.\n", Type);
  138.   abort ();
  139. }
  140.  
  141.  
  142. // resize_error -- Error message for parameterized CoolQueue<Type>::resize() method
  143. // Input:          Character string of type
  144. // Output:         None
  145.  
  146. void CoolQueue::resize_error (const char* Type) {
  147.   //RAISE (Error, SYM(CoolQueue), SYM(Static_Size),
  148.   printf ("CoolQueue<%s>::resize(): Static-size queue.\n", Type);
  149.   abort ();
  150. }
  151.  
  152.  
  153. // assign_error -- Error message for parameterized CoolQueue<Type>::operator=()
  154. // Input:          Character string of type
  155. // Output:         None
  156.  
  157. void CoolQueue::assign_error (const char* Type) {
  158.   //RAISE (Error, SYM(CoolQueue), SYM(Static_Size),
  159.   printf ("CoolQueue<%s>::operator=(): Static-size queue.\n", Type);
  160.   abort ();
  161. }
  162.